USE [OLAP]
GO
/****** Object:  Table [dbo].[city]    Script Date: 5/23/2013 21:04:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[city](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[name] [nchar](200) NULL,
 CONSTRAINT [PK_city] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[country]    Script Date: 5/23/2013 21:04:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[country](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[name] [nchar](200) NULL,
 CONSTRAINT [PK_country] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[property]    Script Date: 5/23/2013 21:04:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[property](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[district] [nchar](200) NULL,
	[price] [decimal](18, 0) NULL,
	[area] [decimal](18, 0) NULL,
	[plotArea] [decimal](18, 0) NULL,
	[bedrooms] [int] NULL,
	[bathrooms] [int] NULL,
	[datetime] [datetime] NULL,
	[id_country] [int] NULL,
	[id_city] [int] NOT NULL,
	[id_type] [int] NULL,
	[id_source] [int] NULL,
 CONSTRAINT [PK_property] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[property] SET (LOCK_ESCALATION = DISABLE)
GO
/****** Object:  Table [dbo].[source]    Script Date: 5/23/2013 21:04:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[source](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[name] [nchar](100) NULL,
 CONSTRAINT [PK_source] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[temp]    Script Date: 5/23/2013 21:04:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[temp](
	[country] [nchar](200) NULL,
	[city] [nchar](200) NULL,
	[district] [nchar](200) NULL,
	[price] [decimal](18, 0) NULL,
	[area] [decimal](18, 0) NULL,
	[plotArea] [decimal](18, 0) NULL,
	[type] [nchar](100) NULL,
	[bedrooms] [int] NULL,
	[bathrooms] [int] NULL,
	[source] [nchar](100) NULL,
	[datetime] [datetime] NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[type]    Script Date: 5/23/2013 21:04:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[type](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[name] [nchar](100) NULL,
 CONSTRAINT [PK_type] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[property]  WITH CHECK ADD  CONSTRAINT [FK_property_city] FOREIGN KEY([id_city])
REFERENCES [dbo].[city] ([id])
GO
ALTER TABLE [dbo].[property] CHECK CONSTRAINT [FK_property_city]
GO
ALTER TABLE [dbo].[property]  WITH CHECK ADD  CONSTRAINT [FK_property_country] FOREIGN KEY([id_country])
REFERENCES [dbo].[country] ([id])
GO
ALTER TABLE [dbo].[property] CHECK CONSTRAINT [FK_property_country]
GO
ALTER TABLE [dbo].[property]  WITH CHECK ADD  CONSTRAINT [FK_property_source] FOREIGN KEY([id_source])
REFERENCES [dbo].[source] ([id])
GO
ALTER TABLE [dbo].[property] CHECK CONSTRAINT [FK_property_source]
GO
ALTER TABLE [dbo].[property]  WITH CHECK ADD  CONSTRAINT [FK_property_type] FOREIGN KEY([id_type])
REFERENCES [dbo].[type] ([id])
GO
ALTER TABLE [dbo].[property] CHECK CONSTRAINT [FK_property_type]
GO
